import { hydrateFiles } from "@grammyjs/files";
import { Bot } from "grammy";

import { mongooseInit } from "./database/mongoose-init.js";
import { MessageMedia } from "./message/media.js";
import { ErrorHandler } from "./error-handler.js";

/** @param {import("../types").IConfig} config */
export async function bootstrap(config) {
  const { token, database } = config;

  await mongooseInit(database.uri, database.options);

  const bot = new Bot(token);

  bot.api.config.use(hydrateFiles(bot.token));

  new MessageMedia(config).handle(bot);
  new ErrorHandler().handle(bot);

  bot.start();
}
